package com.ll.example.springbootwebdemokotlin.controller

import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestParam
import javax.servlet.http.HttpSession

@Controller
class LoginController {
    /**
     * 处理登陆请求
     */
//    @RequestMapping(value = "/user/login",method = [RequestMethod.POST])
    @PostMapping("/user/login")
    fun login(@RequestParam("username") userName:String,
              @RequestParam("password") password:String,
              msg:HashMap<String,String>,
              httpSession: HttpSession):String{

         userName?.let {
             return if (password == "123456"){
                 //登陆成功以后，防止表单重复提交，可以重定向到主页
                 httpSession.setAttribute("loginuser",userName)
                 "redirect:/main.html"
             }else{
                 msg["msg"]="用户名密码错误"
                 "login"
             }
         }
         userName.let {
             msg["msg"]="用户名不能为空"
             return "login"
         }
    }
}